package com.smartcampusbackend.mapper;

import com.smartcampusbackend.model.OperationLog;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface OperationLogMapper {
    @Insert("INSERT INTO operation_log (business_type, business_id, operation_type, operator_id, operator_name, operator_role, content, status, is_signature, create_time) " +
            "VALUES (#{businessType}, #{businessId}, #{operationType}, #{operatorId}, #{operatorName}, #{operatorRole}, #{content}, #{status}, #{isSignature}, #{createTime})")
    int insert(OperationLog log);

    @Select("<script>" +
            "SELECT * FROM operation_log WHERE 1=1" +
            "<if test='businessType != null and businessType != \"\"'> AND business_type = #{businessType} </if>" +
            "<if test='operatorRole != null and operatorRole != \"\"'> AND operator_role = #{operatorRole} </if>" +
            "<if test='operationType != null and operationType != \"\"'> AND operation_type = #{operationType} </if>" +
            "<if test='businessId != null and businessId != \"\"'> AND business_id = #{businessId} </if>" +
            "<if test='status != null and status != \"\"'> AND status = #{status} </if>" +
            "<if test='startTime != null and startTime != \"\"'> AND create_time &gt;= #{startTime} </if>" +
            "<if test='endTime != null and endTime != \"\"'> AND create_time &lt;= #{endTime} </if>" +
            "ORDER BY create_time DESC" +
            "</script>")
    List<OperationLog> queryLogs(@Param("businessType") String businessType,
                                 @Param("operatorRole") String operatorRole,
                                 @Param("operationType") String operationType,
                                 @Param("businessId") String businessId,
                                 @Param("status") String status,
                                 @Param("startTime") String startTime,
                                 @Param("endTime") String endTime);
} 